<?php namespace app\admin\controller;

class Link extends Common {
    protected $db;
    public function __init(){
       $this->db=new \system\model\Link();
	}
    //动作
    public function index(){
       $data=Db::table('link')->get();
//       p($data);
       View::with('data',$data);
	   return view();
    }
    //添加链接
    public function store(){
       if (IS_POST){
          $res=$this->db->store();
//          var_dump($res);die;
		  if ($res) {
			 message('添加失败', 'back', 'error');
		  }
		  message('添加成功', u('index'), 'success');
	   }
       return view();
	}

	//编辑
    public function edit(){
       $lid=q('get.lid');
       if (IS_POST){
          $res=$this->db->edit();
          if ($res['valid']==1){
             message($res['message'],u('index'),'success');
		  }
		  message($res['message'],'back','success');
	   }
       //获取旧数据
       $oldData=Db::table('link')->where('lid',$lid)->first();
//       p($oldData);
       View::with('oldData',$oldData);
       return view();
	}

    //删除
   public function del(){
       $lid=q('get.lid');
       $res=$this->db->where('lid',$lid)->delete();
       if ($res){
		  message('删除成功',u('index'),'success');
	   }
	   message('删除失败','back','success');
   }
}
